home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8310 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.9 KB

  1. Path: newshost.lanl.gov!tanmoy
  2. From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: macro that return value, how?
  5. Date: 01 Mar 1996 00:17:49 GMT
  6. Organization: Los Alamos National Laboratory
  7. Message-ID: <TANMOY.96Feb29171749@qcd.lanl.gov>
  8. References: <3133e87b.868433@news.csus.edu>
  9. NNTP-Posting-Host: qcd.lanl.gov
  10. Mime-Version: 1.0
  11. Content-Type: text
  12. In-reply-to: wleong@sfsu.edu's message of Wed, 28 Feb 1996 05:35:35 GMT
  13.  
  14. In article <3133e87b.868433@news.csus.edu>
  15. wleong@sfsu.edu (Jerry Leong) writes:
  16.  
  17. JL: 
  18. JL: Hi,
  19. JL:     I need to define a macro that will first calculate a given a
  20. JL: parameter and then return it. How can I do that?
  21. JL: 
  22. JL: p/s: Say I pass a value to the macro, macro will perform some
  23. JL: addition, then return the value.
  24. JL: 
  25. JL: #define add1(x)  { x+=VAR; return x; }   
  26. JL: 
  27. JL: something like that by the above does not compile.
  28. JL: Thanx in advance!
  29.  
  30. I think, but am not sure, that you have misunderstood the concept of
  31. macros. Macros never calculate anything, they replace the pp-tokens
  32. that you type in (e.g. add1 followed by ( followed by x followed by ))
  33. by another set of pp-tokens that it generates (e.g. the pp-tokens: {
  34. x += VAR ; return x ; }) before the stream is analyzed for the meaning of
  35. the program. If you could have written { x+=VAR; return x; } in some
  36. place, you can also write add1(x) at the same point (with the above
  37. definition).
  38.  
  39. In other words, macros are substitution rules, not calculators.
  40.  
  41. Cheers
  42. Tanmoy
  43. --
  44. tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
  45. Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
  46. Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
  47. <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
  48. internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
  49. fax: 1 (505) 665 3003   voice: 1 (505) 665 4733    [ Home: 1 (505) 662 5596 ]
  50.